from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-22 14:02:45.409662
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 22, Aug, 2022
Time: 14:02:50
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1926
Nobs: 756.000 HQIC: -50.5313
Log likelihood: 9616.59 FPE: 9.17012e-23
AIC: -50.7435 Det(Omega_mle): 8.14727e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296240 0.055076 5.379 0.000
L1.Burgenland 0.107298 0.036576 2.934 0.003
L1.Kärnten -0.106891 0.019412 -5.506 0.000
L1.Niederösterreich 0.208229 0.076377 2.726 0.006
L1.Oberösterreich 0.107880 0.074283 1.452 0.146
L1.Salzburg 0.253955 0.039115 6.493 0.000
L1.Steiermark 0.037195 0.051017 0.729 0.466
L1.Tirol 0.108401 0.041331 2.623 0.009
L1.Vorarlberg -0.060105 0.035503 -1.693 0.090
L1.Wien 0.052434 0.065961 0.795 0.427
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063030 0.114659 0.550 0.583
L1.Burgenland -0.033514 0.076145 -0.440 0.660
L1.Kärnten 0.046985 0.040413 1.163 0.245
L1.Niederösterreich -0.175861 0.159003 -1.106 0.269
L1.Oberösterreich 0.400506 0.154645 2.590 0.010
L1.Salzburg 0.288558 0.081431 3.544 0.000
L1.Steiermark 0.106187 0.106208 1.000 0.317
L1.Tirol 0.314098 0.086044 3.650 0.000
L1.Vorarlberg 0.026349 0.073912 0.356 0.721
L1.Wien -0.028690 0.137320 -0.209 0.835
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189894 0.028284 6.714 0.000
L1.Burgenland 0.089751 0.018783 4.778 0.000
L1.Kärnten -0.008841 0.009969 -0.887 0.375
L1.Niederösterreich 0.260506 0.039222 6.642 0.000
L1.Oberösterreich 0.135124 0.038147 3.542 0.000
L1.Salzburg 0.045757 0.020087 2.278 0.023
L1.Steiermark 0.018376 0.026199 0.701 0.483
L1.Tirol 0.093661 0.021225 4.413 0.000
L1.Vorarlberg 0.058451 0.018232 3.206 0.001
L1.Wien 0.118497 0.033873 3.498 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107377 0.028787 3.730 0.000
L1.Burgenland 0.046508 0.019117 2.433 0.015
L1.Kärnten -0.014378 0.010146 -1.417 0.156
L1.Niederösterreich 0.192120 0.039920 4.813 0.000
L1.Oberösterreich 0.292490 0.038826 7.533 0.000
L1.Salzburg 0.111251 0.020445 5.442 0.000
L1.Steiermark 0.102556 0.026665 3.846 0.000
L1.Tirol 0.108894 0.021603 5.041 0.000
L1.Vorarlberg 0.069921 0.018557 3.768 0.000
L1.Wien -0.017522 0.034476 -0.508 0.611
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128157 0.052207 2.455 0.014
L1.Burgenland -0.050930 0.034671 -1.469 0.142
L1.Kärnten -0.040626 0.018401 -2.208 0.027
L1.Niederösterreich 0.171278 0.072399 2.366 0.018
L1.Oberösterreich 0.140036 0.070414 1.989 0.047
L1.Salzburg 0.288448 0.037078 7.780 0.000
L1.Steiermark 0.033557 0.048359 0.694 0.488
L1.Tirol 0.162491 0.039178 4.148 0.000
L1.Vorarlberg 0.100765 0.033654 2.994 0.003
L1.Wien 0.068836 0.062525 1.101 0.271
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056565 0.041645 1.358 0.174
L1.Burgenland 0.040336 0.027656 1.458 0.145
L1.Kärnten 0.050311 0.014678 3.428 0.001
L1.Niederösterreich 0.220932 0.057751 3.826 0.000
L1.Oberösterreich 0.286117 0.056168 5.094 0.000
L1.Salzburg 0.045123 0.029576 1.526 0.127
L1.Steiermark -0.001301 0.038576 -0.034 0.973
L1.Tirol 0.147305 0.031252 4.714 0.000
L1.Vorarlberg 0.072641 0.026845 2.706 0.007
L1.Wien 0.082792 0.049876 1.660 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177598 0.049751 3.570 0.000
L1.Burgenland -0.003708 0.033040 -0.112 0.911
L1.Kärnten -0.062080 0.017535 -3.540 0.000
L1.Niederösterreich -0.080270 0.068992 -1.163 0.245
L1.Oberösterreich 0.193338 0.067101 2.881 0.004
L1.Salzburg 0.057267 0.035333 1.621 0.105
L1.Steiermark 0.231657 0.046084 5.027 0.000
L1.Tirol 0.496079 0.037335 13.287 0.000
L1.Vorarlberg 0.046996 0.032071 1.465 0.143
L1.Wien -0.054605 0.059583 -0.916 0.359
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165411 0.057306 2.886 0.004
L1.Burgenland -0.010736 0.038057 -0.282 0.778
L1.Kärnten 0.067136 0.020198 3.324 0.001
L1.Niederösterreich 0.206082 0.079468 2.593 0.010
L1.Oberösterreich -0.068510 0.077291 -0.886 0.375
L1.Salzburg 0.210714 0.040699 5.177 0.000
L1.Steiermark 0.116585 0.053082 2.196 0.028
L1.Tirol 0.070974 0.043004 1.650 0.099
L1.Vorarlberg 0.121831 0.036941 3.298 0.001
L1.Wien 0.122161 0.068631 1.780 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360104 0.032926 10.937 0.000
L1.Burgenland 0.007420 0.021866 0.339 0.734
L1.Kärnten -0.023609 0.011605 -2.034 0.042
L1.Niederösterreich 0.214318 0.045660 4.694 0.000
L1.Oberösterreich 0.194073 0.044408 4.370 0.000
L1.Salzburg 0.044918 0.023384 1.921 0.055
L1.Steiermark -0.015568 0.030499 -0.510 0.610
L1.Tirol 0.105760 0.024708 4.280 0.000
L1.Vorarlberg 0.072872 0.021225 3.433 0.001
L1.Wien 0.041522 0.039433 1.053 0.292
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040189 0.144802 0.192685 0.154724 0.122650 0.108454 0.065147 0.220956
Kärnten 0.040189 1.000000 -0.005564 0.133172 0.039901 0.095397 0.431567 -0.053065 0.098666
Niederösterreich 0.144802 -0.005564 1.000000 0.337097 0.144672 0.297859 0.101431 0.181534 0.317345
Oberösterreich 0.192685 0.133172 0.337097 1.000000 0.227222 0.330599 0.173368 0.167032 0.263614
Salzburg 0.154724 0.039901 0.144672 0.227222 1.000000 0.145530 0.117173 0.145825 0.126364
Steiermark 0.122650 0.095397 0.297859 0.330599 0.145530 1.000000 0.149317 0.137060 0.076440
Tirol 0.108454 0.431567 0.101431 0.173368 0.117173 0.149317 1.000000 0.113612 0.146995
Vorarlberg 0.065147 -0.053065 0.181534 0.167032 0.145825 0.137060 0.113612 1.000000 0.003625
Wien 0.220956 0.098666 0.317345 0.263614 0.126364 0.076440 0.146995 0.003625 1.000000